<?php
include("../common.inc.php");
InitGP(array("page","action","aid","delids")); //初始化变量全局返回
include("function_common.php");
//初始化对象
include(INC_PATH."/admin.class.php");
$a=new AdminClass();


if(empty($action)){
	InitGP(array("user")); //初始化变量全局返回
	if(!empty($user))$wherestr[]="user like '%{$user}%'";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总
	
	//获取当前页码
	$total=$a->getcount($wheresql); 							  //总信息数
	$pagesize=15;												  //一页显示信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$a->getdata("$offset,$pagesize",$wheresql); //获取团购数据
	
	//包含后台模板文件
	include("tpl/sys_admin.htm");
	
}elseif ($action=="edit") {
	InitGP(array("aid","user","password","oldpassword","Submit")); //初始化变量全局返回
	if(!empty($Submit)){
		if (empty($password))$password=$oldpassword;else $password=md5(md5($password));//两次md5加密
		$addarray=array(
			"password"=>$password,
		);
		
		$info=$a->edit($aid,$addarray);
		if($info=="OK"){showmsg("编辑成功!","sys_admin.php");//成功
		}else showmsg($info,"-1");//出错！

	}else {
	
	//编辑信息表单
	$dataedit=$a->getdata(1,"aid={$aid}");
	$value=$dataedit[0];//获取第一条记录
	//包含后台模板文件
	include("tpl/sys_admin.htm");	
	}
	
}elseif ($action=="add") {	
	InitGP(array("user","password","Submitadd")); //初始化变量全局返回
	if(!empty($Submitadd)){
		$password=md5(md5($password));//两次md5加密
		$addarray=array(
			"user"=>$user,
			"password"=>$password,
			"lastlogin"=>$timestamp
		);
		$info=$a->add($addarray);
		if($info=="OK"){showmsg("添加成功!","sys_admin.php");//成功
		}else showmsg($info,"-1");//出错！	

	}else {
		include("tpl/sys_admin.htm");	
	}
}elseif ($action=="del" && !empty($uid)){
	//执行删除操作
	$uid=GetNum($uid);
	$info=$a->del($uid);
	if($info=="OK")showmsg("删除管理用户成功！","sys_admin.php");
	else showmsg($info,"sys_admin.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","sys_admin.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$a->del($id);
	}
	if($info=="OK")showmsg("删除管理用户成功！","sys_admin.php");
	else showmsg($info,"-1");
}

?>

